package com.healthcloud.service.accompany.impl;

import com.healthcloud.dao.accompany.AccompanyBfDao;
import com.healthcloud.entity.HlDoctorEntity;
import com.healthcloud.entity.accompany.AccompanyBfEntity;
import com.healthcloud.entity.accompany.AccompanyBfVo;
import com.healthcloud.service.HlDoctorService;
import com.healthcloud.service.accompany.AccompanyBfService;
import com.healthcloud.utils.PageParam;
import com.healthcloud.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("accompanyBfService")
@Transactional
public class AccompanyBfServiceImpl implements AccompanyBfService {
	@Autowired
	private AccompanyBfDao accompanyBfDao;

	@Autowired
	private HlDoctorService hlDoctorService;
	
	@Override
	public AccompanyBfVo queryObjectVo(Long id){
		return accompanyBfDao.queryObjectVo(id);
	}
	
	@Override
	public List<AccompanyBfVo> queryListVo(AccompanyBfVo entity, PageParam pageParam){
		return accompanyBfDao.queryListVo(entity, pageParam);
	}
	
	@Override
	public int queryTotalVo(AccompanyBfVo entity){
		return accompanyBfDao.queryTotalVo(entity);
	}
	
	@Override
	public void save(AccompanyBfEntity accompanyBf){
		accompanyBfDao.save(accompanyBf);
	}
	
	@Override
	public void update(AccompanyBfEntity accompanyBf){
		accompanyBfDao.update(accompanyBf);
	}
	
	@Override
	public void delete(Integer id){
		accompanyBfDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		accompanyBfDao.deleteBatch(ids);
	}

	@Override
	public void saveOrUpdate(AccompanyBfEntity entity) {
		if (entity.getId()==null){
			saveByDoctor(entity);
		}else {
			update(entity);
		}
	}

	private void saveByDoctor(AccompanyBfEntity accompanyBf) {
		Long userId = ShiroUtils.getUserId();
		HlDoctorEntity doctor = hlDoctorService.queryByUserId(userId);
		if (doctor!=null){
			accompanyBf.setDoctorId(doctor.getId());
		}
		save(accompanyBf);
	}

	@Override
	public List queryRemindList(AccompanyBfVo entity, PageParam pageParam) {
		return accompanyBfDao.queryRemindList(entity, pageParam);
	}

	@Override
	public Integer queryRemindTotal(AccompanyBfVo entity) {
		return accompanyBfDao.queryRemindTotal(entity);
	}

}
